<?php
namespace Home\Controller;
use Think\Controller;
use Think\Upload;

class CateController extends Controller {
	
	public function __construct(){
		parent::__construct();
		
		if(empty($_SESSION['user']))
		{
			 $this->error('对不起,您还没有登录!请先登录!', U('Login/login'), 1);
			
		}
	}


	public function lst(){
		$book=M('book_cate');
		$res = $book->select();
		$this->assign('res',$res);
		
		$this->display();
	}

	


	public function add(){
		$book=M('book_cate');

		if(IS_POST){

			$data = I('post.','','htmlspecialchars');
			
	   	    	
	    	//dump($data);die;
	    	$res = $book->add($data);
	    	if($res){
	    		$this->success('添加成功',U('lst'),2);
	    	}else{
	    		$this->error('添加失败','',2);
	    	}

		
		}
		$this->display();

	}

	public function edit(){
		$book=M('book_cate');

		if(IS_POST){
			$data = I('post.');
			//dump($data);die;
			$res = $book->save($data);
			if($res!==false){
				$this->success('修改成功');
			}else{
				$this->error('修改失败');
			}

		}

		$eid = I('get.eid');
	    $res = $book->find($eid);
	    	
		$this->assign('res',$res);
		$this->display();

	}

	public function del($id){
		$book=M('book_cate');
		$book->delete($id);
		$this->success('删除成功',U('lst'));
	}

}